<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<FileCreateInput>" %>
<% using (Html.BeginForm())
       {    %>
    <%=Html.HiddenFor(o => o.EntityId) %>
    <div class='ia'>
        <%=Html.EditorFor(o => o.Title) %>
        <%=Html.EditorFor(o => o.Subject) %>
        <%=Html.EditorFor(o => o.RegisteredOn) %>
        <%=Html.EditorFor(o => o.Source) %>
        <%=Html.EditorFor(o => o.SourceProtocolNumber) %>
    </div>
    <div class='ia'>        
        <%=Html.EditorFor(o => o.LanguageId) %>
        <%=Html.EditorFor(o => o.InternalProtocolNumber) %>
        <%=Html.EditorFor(o => o.ProtocolNumber) %>
        <div class="efield">
            <div class="elabel">
                Fisier:</div>
            <div class="einput">
                <input type='text' disabled="disabled" id="fileDisplay" /></div>
        </div>
        <%=Html.HiddenFor(o => o.Name) %>
        <%=Html.HiddenFor(o => o.ContentType) %>
    </div>
    <% }%>
    <div class="ia">
        <form id="file_upload" action="<%=Url.Action("upload") %>" method="post" enctype="multipart/form-data" style="margin:1em;">
        <input type="file" name="file" />
        <button>
            Incarca</button>
        <div>
            Incarca fisier</div>
        </form>
        <table id="files">
        </table>
        <%=Html.ValidationMessageFor(o => o.Name) %>
    </div>
    <script type="text/javascript">
        $(function () {
            $('#fileDisplay').val($('#Name').val().substring(36));

            $('#file_upload').fileUploadUI({
                url: '<%=Url.Action("upload") %>',
                uploadTable: $('#files'),
                downloadTable: $('#files'),
                buildUploadRow: function (files, index) {
                    return $('<tr><td>' + files[index].name + '<\/td>' +
                    '<td class="file_upload_progress"><div><\/div><\/td>' +
                    '<td class="file_upload_cancel">' +
                    '<button class="ui-state-default ui-corner-all" title="Cancel">' +
                    '<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
                    '<\/button><\/td><\/tr>');
                },
                buildDownloadRow: function (file) {
                    $('#Name').val(file.name);
                    $('#ContentType').val(file.type);
                    $('#fileDisplay').val(file.name.substring(36));
                    return $('');
                },
                addNode: function (parentNode, node, callBack) {
                    parentNode.empty();
                    parentNode.append(node);
                    if (typeof callBack === 'function') {
                        callBack();
                    }
                }
            });
        });
    </script>